Skip to content

AppStoreの署名検証・CSRF・CORS・アップロード検査を強化#8

Merged
tas0dev merged 6 commits into
mochiOS:mainfrom
minto-dane:main
Jun 13, 2026
Merged

AppStoreの署名検証・CSRF・CORS・アップロード検査を強化#8
tas0dev merged 6 commits into
mochiOS:mainfrom
minto-dane:main

Conversation

@minto-dane

Copy link
Copy Markdown
Contributor

概要

mochiOS AppStore / Developer Console / API の主要なWebセキュリティリスクを修正しました。

主な変更は以下です。

  • package署名検証を、developerが登録したactive公開鍵にbind
  • msign verify に登録済み公開鍵を渡す検証経路を追加
  • CSRF token発行・検証を追加
  • credentialed CORSを設定由来に一元化し、productionでlocalhostを除外
  • session cookie属性、OAuthログイン後のsession再生成、logout処理を強化
  • package inspectにDoS/path traversal対策を追加
  • PAX/global extended tar header、duplicate path、大量entryを拒否
  • revoked signing keyでrelease submit / approveできないよう再確認
  • admin / CA操作の監査ログを追加
  • CA発行・失効をowner roleに限定
  • security headersをApache/nginx設定に追加
  • 公開検索UIの明確なDOM XSSを修正
  • セキュリティ回帰テストを追加

脅威モデル

このPRでは、以下の攻撃を主に防ぎます。

  • package内の public_key を攻撃者の鍵に差し替え、key_id だけ登録済みに見せる署名検証バイパス
  • revoked keyで作成済みreleaseを後からsubmit/approveする攻撃
  • session cookie認証APIに対するCSRF
  • 本番APIが不要なlocalhost originへcredentialed CORSを返す設定ミス
  • OAuth開始URLをcross-siteに踏ませて既存stateを上書きする妨害
  • tar.gz packageのPAX header / duplicate path / 大量entry / サイズ爆弾による検査回避やDoS
  • admin / CA操作の監査不能
  • 検索UIでの入力値由来DOM XSS

実装メモ

  • msignAPPSTORE_MSIGN_PATH またはconfigの msign_path で指定できます。
  • package_hash は後方互換のため残し、現状は content_hash 相当としてdocsに明記しています。
  • audit log用に audit_logs テーブルを追加しました。
  • migrationは CREATE TABLE IF NOT EXISTS / CREATE INDEX IF NOT EXISTS を使っており、同じDBに2回流してもエラーにならないことを確認済みです。

テスト

追加・更新した主なテスト:

  • CSRF tokenなしPOST拒否
  • bad Origin / Sec-Fetch-Site: cross-site 拒否
  • cross-site OAuth開始拒否
  • revoked signing keyでsubmit / approve拒否
  • fake msign による --pubkey bind確認
  • public key形式検証
  • production CORSでlocalhostが許可されないこと
  • 正常pkg inspect
  • duplicate path拒否
  • PAX header拒否
  • 大量directory entry拒否
  • CA issue/revokeのaudit log確認

実行した確認:

make test
find src -type f -name '*.php' -print | sort | xargs -n1 php -l
git diff --check

結果:

All tests passed

migration再実行確認:

APPSTORE_DATA_DIR=/tmp/... make migrate
APPSTORE_DATA_DIR=/tmp/... make migrate

結果:

Migration complete
Migration complete

残る制約

  • msign と実署名済み .pkg を使ったE2E fixtureは未追加です。
  • 既存DBに旧形式fingerprintのpublic keyがある場合の移行migrationは未追加です。
  • CSPはinline scriptが残るため、今回は frame-ancestors / object-src / base-uri 中心の段階導入です。

@tas0dev tas0dev self-requested a review June 12, 2026 23:39

@tas0dev tas0dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

気になる箇所があるので修正してください。また、apiを追加したのならばOpenAPIに書き加えるべきです。

Comment thread config/app.example.php Outdated
Comment thread src/api/cors.php
Comment thread src/cli/migrate.php Outdated
@tas0dev tas0dev self-requested a review June 13, 2026 02:10

@tas0dev tas0dev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとう、非常に良いと思います。
感謝します。

@tas0dev tas0dev added enhancement New feature or request good first issue Good for newcomers labels Jun 13, 2026
@tas0dev tas0dev merged commit a5774c5 into mochiOS:main Jun 13, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants